<template>
    <ShopPageHead></ShopPageHead>
    <main class="index_main" id="all_vue">
        <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
        <ShopSubMenu></ShopSubMenu>
        <!-- 当前位置 -->

        <div class="categ_crumb_box clearfix_2 phone_none">
            <div class="categ_crumb_left">

                <span class="categ_crumb_left_a" title=""> 当前位置： </span>
                <NuxtLink
                    :to="`/xiangcunshangcheng/index.html`"
                    class="categ_crumb_left_a"
                >
                        乡村商城
                    </NuxtLink>
                &gt;
                <NuxtLink
                    :to="`/xiangcunshangcheng/${targetSegment}/index.html`"
                    class="categ_crumb_left_a"
                >
                    {{name}}
                </NuxtLink>
                &gt;
                <NuxtLink
                    :to="`/xiangcunshangcheng/${targetSegment}/gongying/list-1.html`"
                    class="categ_crumb_left_a"
                >
                    供应
                </NuxtLink>
                &gt;
                <span class="categ_crumb_left_text">{{shopData.name}}</span>
            </div>
        </div>

        <div class="breadcrumb_box pc_none">
        
            <span class=" ">当前位置:</span>
            
            <NuxtLink
                :to="`/xiangcunshangcheng/index.html`"
                class="categ_crumb_left_a"
                >
                乡村商城
            </NuxtLink>
            <span class=" ">&gt;</span>

            <NuxtLink
                    :to="`/xiangcunshangcheng/${targetSegment}/index.html`"
                    class="categ_crumb_left_a"
            >
                    {{name}}
            </NuxtLink>
            <span class=" ">&gt;</span>

            <NuxtLink
                    :to="`/xiangcunshangcheng/${targetSegment}/gongying/list-1.html`"
                    class="categ_crumb_left_a"
                >
                    供应
            </NuxtLink>
            <span class=" ">&gt;</span>

            <span class="">{{shopData.name}}</span>
            
        </div>

        <div class="supply_1_index clearfix">
            <img class="supply_1_img" :src="shopImg" :alt="shopData.name">
            <div class="supply_1_right">
                <h4 class="supply_1_h4">{{shopData.name}}</h4>
                <div class="supply_1_title_box clearfix">
 
                    <time class="supply_1_title phone_none"> 更新日期：{{shopData.updated_at}}</time>

                    <time class="supply_1_title pc_none"> {{shopData.updated_at}}</time>
                    <span class="supply_1_title">浏览次数：{{ shopData.hits }}</span>
                </div>
                <div class="supply_1_ul clearfix">
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">公 司 名</label><span
                            class="supply_1_li_text ">{{ shopData.com }}</span></div>
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">所 在 地</label><span
                            class="supply_1_li_text ">{{ shopData.address }}</span></div>
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">联 系 人</label><span
                            class="supply_1_li_text ">{{ shopData.contact}}</span></div>
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">产品单价</label><span
                            class="supply_1_li_text ">{{shopData.price}}元/{{ shopData.unit }}</span></div>
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">最小定量</label><span
                            class="supply_1_li_text ">{{ shopData.min }}</span></div>
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">供货总量</label><span
                            class="supply_1_li_text ">{{shopData.max}}</span></div>
                    <div class="supply_1_li clearfix"><label class="supply_1_li_label">有 效 期</label><span
                            class="supply_1_li_text ">{{getValidityTime(shopData)}}</span></div>
                </div>
            </div>
        </div>
        <div class="supply_2_index clearfix phone_none">

            <div class="supply_head_box clearfix_2">

                <a class="supply_head_a" title="" :class="{ supply_head_a_only: 1 == supply_choice_1_num }"
                    @mouseover="supply_choice_1_num = 1">详情信息</a>
                <a class="supply_head_a" title="" :class="{ supply_head_a_only: 2 == supply_choice_1_num }"
                    @mouseover="supply_choice_1_num = 2">联系方式</a>
                <a class="supply_head_a" title="" :class="{ supply_head_a_only: 3 == supply_choice_1_num }"
                    @mouseover="supply_choice_1_num = 3">图片展示</a>
            </div>

            <div class="supply_art_out clearfix">
                

                <!-- 详情信息 -->
                <div class="supply_art_box" v-show="supply_choice_1_num == 1" v-html="shopData.detail"></div>
                <!-- 联系方式 -->
                <div class="supply_art_box" v-show="supply_choice_1_num == 2">
                    <p class="supply_art_box_p">公司名：{{ shopData.com }}</p>
                    <p class="supply_art_box_p">联系人：{{shopData.contact}}</p>
                    <p class="supply_art_box_p">电话：{{shopData.phone}}</p>
                    <p class="supply_art_box_p">邮箱：{{shopData.email}}</p>
                    <p class="supply_art_box_p">邮政编码：{{shopData.postal}}</p>
                    <p class="supply_art_box_p">详细地址：{{shopData.address}}</p>
                </div>
                <!-- 图片展示 -->
                <div class="supply_art_box" v-show="supply_choice_1_num == 3">
                    <div class="supply_art_box_img">
                        <img :src="item" v-for="item in shopData.imgurl">
                    </div>
                </div>
            </div>

       </div>

        <!-- 手机选项卡 btn phone -->
        <div class="phone_box_1_head pc_none">
                
            <a :class="{ a_choice_only: 1 == supply_choice_1_num }"
                @mouseover="supply_choice_1_num = 1">详情信息</a>
            <a :class="{ a_choice_only: 2 == supply_choice_1_num }"
                @mouseover="supply_choice_1_num = 2">联系方式</a>
            <a :class="{ a_choice_only: 3 == supply_choice_1_num }"
                @mouseover="supply_choice_1_num = 3">图片展示</a>
        </div>
        <!-- 手机选项卡 card phone -->
        <div class="pc_none">
            <!-- 详情信息 phone -->
            <div class="phone_box_1 pc_none" v-show="supply_choice_1_num == 1">

    
                <div class="phone_box_1_text" v-html="shopData.detail"></div>

            </div>

            <!-- 联系方式 phone -->
            <div class="phone_box_2 pc_none" v-show="supply_choice_1_num == 2">
                
                <div class="phone_box_2_text">

                    <div class="phone_box_2_li"><label class="phone_box_2_li_label">公司名:</label> <span class="phone_box_2_li_text">{{ shopData.com }}</span></div>
                    <div class="phone_box_2_li"><label class="phone_box_2_li_label">联系人:</label> <span class="phone_box_2_li_text">{{ shopData.contact }}</span></div>
                    <div class="phone_box_2_li"><label class="phone_box_2_li_label">电话:</label> <span class="phone_box_2_li_text">{{ shopData.phone }}</span></div>
                    <div class="phone_box_2_li"><label class="phone_box_2_li_label">邮箱:</label> <span class="phone_box_2_li_text">{{ shopData.email }}</span></div>
                    <div class="phone_box_2_li"><label class="phone_box_2_li_label">邮政编码:</label> <span class="phone_box_2_li_text">{{ shopData.postal }}</span></div>
                    <div class="phone_box_2_li"><label class="phone_box_2_li_label">详细地址:</label> <span class="phone_box_2_li_text">{{ shopData.address }}</span></div>
    
                </div>

            </div>

            <!-- 图片展示 phone -->
            <div class="phone_box_3 pc_none" v-show="supply_choice_1_num == 3">
    
    
                <div class="phone_box_3_img_ul">
                            <img :src="item" v-for="item in shopData.imgurl">
                </div>

            </div>
        </div>



        <ShopHotNews></ShopHotNews>
    </main>
    <HomeFoot></HomeFoot>
</template>

<script setup>
//1.页面必备方法 start ---------------------------------------->
import { ref, onMounted } from 'vue'
import { ElRadio, ElRadioGroup } from 'element-plus'
//1.2选项卡 
const supply_choice_1_num = ref(1)
//1.3是否展示有效期
const getValidityTime = (shopData) => {
    if(shopData.islong==1){
        return "无期限"
    }else{
        if(shopData.validity){
            return shopData.validity.split(' ')[0];
        }
    }
}
//1.页面必备方法 end ---------------------------------------->

//2.页面路径 start ---------------------------------------->
//2.1 获得页面数据id
const route = useRoute();
const router = useRouter()
let articleId = 0; //把路径转换为数据id
const name = ref('') //当前频道名称
const targetSegment = getRoutePath(2);//返回第二层的路径id
const targetRoute = getRoutePath(1);//返回第一层的路径id
const towgetRoute = targetRoute + "/" + targetSegment;

//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': towgetRoute,
    },
});
if(getRouteId.code == 200){
    articleId = getRouteId.data.category_id;
    name.value = getRouteId.data.alias;
}else{
    console.log("错误位置：获得页面路径")
}

//2.3 获得子栏目列表
const secondNav = ref([]);
const selectedSecondId = ref(route.query.catid);//当前选中了哪个子导航
let getSecondNav = async () => {
    const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'placeid': 1,
            'pid': articleId,
            'num': 50,
        },
    });
    if (listData.code == 200) {
        secondNav.value = listData.data
    } else {
        console.log("错误位置：获得子级栏目列表")
    }
}
getSecondNav();

//2.4 获得cityid
const cityId = ref(route.query.cityid)
//2.页面路径 end ---------------------------------------->

//3.获得商品详情 start ---------------------------------------->
const shopId = ref(route.params.id) //获得商品的id
const shopData = ref({});
const shopImg = ref("")

let getShopData = async () => {
    const shopReq = await requestDataPromise('/web/getWebsiteshopInfo', {
        method: 'GET',
        query: {
            'id': parseFloat(shopId.value),
        },
    });

    if (shopReq.code == 200) {
        console.log(667788)
        console.log(shopReq)
        shopData.value = shopReq.data
        shopImg.value = shopReq.data.imgurl[0]
    } else {
        console.log("错误位置：获得商品详情")
    }
}
getShopData();
//3.获得商品详情 end  ---------------------------------------->

//5.广告 start ---------------------------------------->
//获得所有广告
let adImg1 = ref({})
onMounted(async () => {
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //从客户端启动广告
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_shopdetail_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];
})
//5.广告 end ---------------------------------------->


//6.设置seo信息 start---------------------------------------->
//6.1 设置seo信息
const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
    method: 'GET',
    query: {
        'catid': articleId
    },
});

if (setData.code == 200) {
    let seoTitle = shopData.value.name;
    let seoDescription = setData.data.seo_description;
    let seoKeywords = setData.data.seo_keywords;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_" +  seoName + "_" + seoSuffix,
        meta: [
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'viewport', content:"width=device-width,initial-scale=1,user-scalable=no"}

        ]
    });
} else {
    // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    // console.log("错误位置：设置列表页面SEO数据")
    // console.log("后端错误反馈：", setData.message)
    // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
}
//6.设置seo信息 end---------------------------------------->

</script>
<style lang="less" scoped>
@import '@/assets/css/shop/detail.less';
</style>


<style lang="less" scoped>

 
    @media screen and (min-width:801px){/*pc*/
         
		
            .pc_none{display:none;}
    }
    @media screen and (max-width:800px){/*ipad_phone*/
 
            .index_main{width:100%;margin-bottom:0px;}
 
            .breadcrumb_box{

                 height:22px;width:100%;margin:10px auto;
                word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
                width:92%;
                font-size:14px;
                color:#666;  
                
                *{
                    font-size:14px;
                     
                    display:inline ;
                    color:#666;  
                    line-height:22px;height:22px;
                    margin-right:5px;
                }

            }

            .supply_1_index{width:92%;margin:0px auto 0px;}
             
            .supply_1_img{width:auto;max-width:100%;height:302px;margin:0px auto 0px;float:none;display:block;border-radius:8px;}
            .supply_1_right{width:100%;margin:0px auto 0px;float:none;}
            .supply_1_h4{font-size:16px;line-height:26px;margin-top:11px;}

            .supply_1_title{font-size:14px;margin-right:10px;}

            .supply_1_li{margin-bottom:20px;width:49%;}
            .supply_1_li:nth-of-type(odd){float:left;}
            .supply_1_li:nth-of-type(even){float:right;}
            
            .supply_1_li:nth-of-type(-n+2){width:100%;}
             




            .supply_1_li .supply_1_li_label{line-height:18px;height:18px;font-size:14px;
                                min-width:auto;margin-right:8px;}
            .supply_1_li .supply_1_li_text{line-height:18px;font-size:14px;flex:1;
                        
                        word-wrap: break-word;
                        overflow-wrap: break-word;
                        white-space: pre-wrap;
                        word-break: break-all;
            }
            .supply_1_li:nth-of-type(n+3) .supply_1_li_text{ height:18px;
                word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
            } 


            .phone_box_1_head{
                    width:92%;margin:0px auto 0px;
                    height:50px;line-height:50px;
                    background:#fff;border-bottom:1px solid #E6E6E6;
                    
                    a{ 
                        float:left;height:50px;line-height:50px;margin:0;position:relative;
                        color:#333;font-size:15px; font-weight:bold;box-sizing:border-box;
                        position:relative;padding-left:30px;
                    }

                    a.a_choice_only{
                        color:#a91b33;
                    }

                    a:nth-child(1)::before{
                        content: '';display: block;
                        position:absolute;left:0px;top:18px;
                        background:#a91b33;
                        width:3px;height:14px;
                    }

                    a:nth-child(1){ 
                        padding-left:8px;
                    }
    
            }

            .phone_box_1{

                    width:92%;margin:0px auto 0px;    
                
                    .phone_box_1_text{ font-size:16px!important;line-height:26px!important;margin-top:15px!important; }
                    .phone_box_1_text *{ font-size:16px!important;line-height:26px!important;margin-top:15px!important; }

            }

            .phone_box_2{

                    width:92%;margin:0px auto 0px;    
                 
                    .phone_box_2_text{
                            margin-top:15px;
                            p{
                                display:block;font-size:16px;line-height:26px;margin-top:5px;
                             
                            }
                    }

                    .phone_box_2_li{
                        display:flex;margin-bottom:10px;
                    }
                    .phone_box_2_li_label{
                        line-height:24px;height:24px;font-size:16px;
                                 margin-right:8px;
                    }
                    .phone_box_2_li_text{
                        line-height:24px;font-size:16px;flex:1;
                        word-wrap: break-word;
                        overflow-wrap: break-word;
                        white-space: pre-wrap;
                        word-break: break-all;
                         
                    }

            }

            .phone_box_3{

                    width:92%;margin:0px auto 0px;    
                    .phone_box_3_head{

                            height:50px;line-height:50px;
                            background:#fff;border-bottom:1px solid #E6E6E6;
                            margin-top:15px;width:100%;
                            
                            a{ 
                                    float:left;height:50px;line-height:50px;margin:0;position:relative;
                                    color:#a91b33;font-size:18px; font-weight:bold;box-sizing:border-box;
                                    position:relative;padding-left:8px;
                            }

                            a::before{
                                content: '';display: block;
                                position:absolute;left:0px;top:15px;
                                background:#a91b33;
                                width:3px;height:20px;
                            }
        
                    }

                    .phone_box_3_img_ul{
                        img{
                           display:block;     
                            margin-top:15px;
                            width:100%;
                        }
                    }
 
            }


            .phone_none{display:none;}
    }


</style>







